#include "mex.h"
#include "math.h"

void mexFunction(int nlhs,mxArray *plhs[], int nrhs, const mxArray *prhs[])

{
        double n,j,*p;
        int i;
        double tmp;
        n=mxGetScalar(prhs[0]);
        plhs[0]=mxCreateDoubleMatrix(1,1,mxREAL);
        p=mxGetPr(plhs[0]);

        j=1.0;
        for (i=n;i>1;i--)
        j=j*i;
//RAND_MAX is a constant defined in <cstdlib>. Its default value may vary between implementations but it is granted to be at least 32767
        tmp=(double) RAND_MAX;
        *p=rand()/tmp;
}
